<template>
	<view>
		<view class="topnav">
			<!-- <uni-nav-bar :fixed="true" title="漫画" leftIcon="left" @clickLeft="clickLeft"></uni-nav-bar> -->
			<uni-nav-bar :fixed="true" title="漫画"></uni-nav-bar>
		</view>
		<view class="sectionBox">
			<uni-section title="文字滚动" subTitle="使用 scrollable 属性使通告滚动,此时 single 属性将失效,始终单行显示" type="line">
				<uni-notice-bar show-icon scrollable show-close text="下拉刷新可随机推荐" />
			</uni-section>
		</view>
		<view class="searchBox">
			<!-- 基本用法 -->
			<uni-search-bar @confirm="search" @input="input"></uni-search-bar>
		</view>
		<view class="categoryBox">
			<uni-section title="基础分组" type="line">
				<uni-group title="漫画">
					<uni-grid v-show="dataList" :column="3" :highlight="true" :square="false" :showBorder="false">
						<uni-grid-item v-for="(item, index) in dataList" :index="index" :key="index"
							@click="goPage(item)">
							<view class="grid-item-box" style="background-color: #fff;">
								<!-- <uni-icons type="image" :size="30" color="#777" /> -->
								<view style="height: 135px; width: 100%;text-align: center;">
									<image style="height: 130px; width: 90%;" :src="item.cover"></image>
								</view>
								<text class="text">{{item.title}}</text>
							</view>
						</uni-grid-item>
					</uni-grid>
					<view v-show="!dataList">
						<text>暂无数据</text>
					</view>
				</uni-group>
			</uni-section>
		</view>
		<view class="">
			<uni-load-more :status="moreMsg"></uni-load-more>
		</view>
	</view>
</template>

<script>
	import {
		getRandomChineseWord
	} from "../../../compoment/index.js"
	export default {
		data() {
			return {
				dataList: [],
				key: "",
				page: 1,
				total: 0,
				moreMsg: "more"
			}
		},
		onLoad() {
			this.search()
		},
		onPullDownRefresh() {
			this.page = 1
			this.dataList = []
			this.search()
		},
		onReachBottom() {
			this.page += 1
			this.search()
		},
		methods: {
			goPage(item){
				uni.navigateTo({
					url:"/pages/index/cartoon/chapter/chapter?item="+JSON.stringify(item) 
				})
			},
			clickLeft() {
				uni.navigateBack()
			},
			search() {
				this.searchBook()
			},
			input(key) {
				this.dataList = []
				this.key = key
			},
			searchBook() {
				this.moreMsg = "loading"
				uni.request({
					url: `https://api.pingcc.cn/comic/search/title/${this.key || getRandomChineseWord()}/${this.page}/12`,
					method: "GET",
					success: ({
						data
					}) => {
						if (!data.data) {
							this.moreMsg = "no-more"
						}
						this.total = data.count
						this.dataList.push(...data.data)
						this.moreMsg = "no-more"
					},
					complete() {
						uni.stopPullDownRefresh()
					}
				})
			}
		}
	}
</script>

<style scoped lang="less">
	image {
		will-change: transform
	}
	.chat-custom-right {
		flex: 1;
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: column;
		justify-content: space-between;
		align-items: flex-end;
	}

	.chat-custom-text {
		font-size: 12px;
		color: #999;
	}

	.image {
		width: 25px;
		height: 25px;
	}

	.text {
		font-size: 14px;
		margin-top: 5px;
	}

	.example-body {
		/* #ifndef APP-NVUE */
		// display: block;
		/* #endif */
	}

	.grid-dynamic-box {
		margin-bottom: 15px;
	}

	.grid-item-box {
		flex: 1;
		// position: relative;
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: column;
		align-items: center;
		justify-content: center;
		padding: 15px 0;
	}

	.grid-item-box-row {
		flex: 1;
		// position: relative;
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: row;
		align-items: center;
		justify-content: center;
		padding: 15px 0;
	}

	.grid-dot {
		position: absolute;
		top: 5px;
		right: 15px;
	}

	.swiper {
		height: 420px;
	}

	/* #ifdef H5 */
	@media screen and (min-width: 768px) and (max-width: 1425px) {
		.swiper {
			height: 630px;
		}
	}

	@media screen and (min-width: 1425px) {
		.swiper {
			height: 830px;
		}
	}

	/* #endif */
</style>
